﻿using System;
using System.Collections.Generic;
using System.Text;
using RobotRace.Geometry;

namespace RobotRace.utils.graph
{
    public class PathGraph
    {
        public Point2D currentCheckpoint { get; private set; }
        public List<Node> nodes { get; private set; }
        private Node firstNode;
        private int internalNodeIdCounter = 0;
        public int Count { get; private set; }

        public PathGraph()
        {
            nodes = new List<Node>();
        }

        public void addNode(Node node)
        {
            if (nodes.Count == 0)
            {
                firstNode = node;
            }
            if (node.nodeNumberOnPath == 0)
            {
                firstNode = node;
            }
            node.nodeID = internalNodeIdCounter++;
            Count = node.nodeNumberOnPath+1;
            this.nodes.Add(node);
        }

        public void addEdge(Node fromNode, Node toNode, double weight)
        {
            Node node = null;
            if (!nodes.Contains(fromNode))
            {
                addNode(fromNode);
            }
            node = nodes[nodes.IndexOf(fromNode)];
            node.addEdgeTo(toNode, weight);
            
        }

        public Node getFirstNodeInSequence()
        {
            return firstNode;
        }

        public Node getNodeWithIdInSequence(int id)
        {
            foreach (Node node in nodes)
            {
                if (node.nodeNumberOnPath == id)
                {
                    return node;
                }
            }
            return null;
        }
    }
}
